// pages/test/test.js
var app = getApp()
var pageChangeUtils = require("../../../utils/pageChangeUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    switchFlag: false,
    lights: "",
    fav: "",
    hadFav: "",
    faved: false, //表示该题已经收藏过的标记
    index: 0
  },

  parentTap: function () {
    const title1 = this.selectComponent("#title1")
    title1.checkDuoxuan()
  },

  zuJianTongXin: function (e) {
    const title1 = this.selectComponent("#title1")
    if (e.detail.type == "lastQuestion") { //触发上一道问题
      this.setData({
        index: this.data.index - 1
      });
      title1._lastQuestion()
    }
    if (e.detail.type == "nextQuestion") {
      this.setData({
        index: this.data.index + 1
      });
      //触发下一道问题
      title1._nextQuestion()
    }
    if (e.detail.type == "bindPickerChange") { //直接设置题目
      title1._bindPickerChange(e.detail.a)
      this.setData({
        index: e.detail.a
      });
    }
  },

  zuJianTongXin2: function (e) {
    const buttom1 = this.selectComponent("#buttom1")
    if (e.detail.type == "swichFlag") {
      this.setData({
        switchFlag: true
      })
      //这里将子组件的SwitchFlag改一下
      buttom1.setData({
        switchFlag: true,
      })
      setTimeout(function () {
        buttom1.setData({
          index: buttom1.data.index + 1
        })
      }, 1900)
    }
    if (e.detail.type == "!swichFlag") {
      this.setData({
        switchFlag: false,
        faved:e.detail.value
      })
      //这里将子组件的SwitchFlag改一下
      buttom1.setData({
        switchFlag: false
      })
    }
    if (e.detail.type == "updateIndex") {
      this.setData({
        index:e.detail.value
      })
      //这里将子组件的SwitchFlag改一下
      buttom1.setData({
        index:e.detail.value
      })
    }
  },

  showRight: function (params) {
    const title1 = this.selectComponent("#title1")
    title1._showRight()
  },



  addFavorite: function () {
    var that = this
    const title1 = this.selectComponent("#title1")
    that.setData({
      faved:!that.data.faved
    })
    title1._addFavorite(that.data.faved)
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title:  app.globalData.selectLib
    })
    let cacheImage = wx.getStorageSync('image')
    this.setData({
      lights: cacheImage.learnCss[0],
      fav: cacheImage.learnCss[1],
      hadFav: cacheImage.learnCss[4],
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})